<?php
require_once 'WebServices.php';

/**
 * class CompanyServiceClient
 *
 */
class CompanyServiceClient {
	
	/**
	 * Search employees
	 *
	 * curl extension must be enable in php.ini
	 *
	 * @return array of employess
	 */
	public static function Select($filters = array()) {
		$ch = curl_init();
		$providers = WebServices::Select($filters);
		
		$data = json_encode($filters);
		$result = array();
		foreach ($providers as $provider) {
			curl_setopt($ch, CURLOPT_URL, $provider['WSURL']);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_POST, 1);
 			curl_setopt($ch, CURLOPT_POSTFIELDS, "method=search&data=$data");

 			$content = curl_exec ($ch);
 			$emps = json_decode($content, true);
 			if ($emps == null) continue;

 			foreach ($emps as &$emp)
 				$emp['Company'] = $provider['Company'];

 			$result = array_merge($result, $emps);
 		}
		
		curl_close ($ch); 
		return $result;
	}
}
?>